<?php

ini_set("display_errors", "On");
error_reporting(E_ALL);

// 引入数据库连接文件
require_once '../../../sql/connection.php';

$id = $_POST['editID'];
$editCourseNumber = $_POST['editCourseNumber'];
$editCourseName = $_POST['editCourseName'];

// 查询语句
$querySql = "select id, create_time, update_time, course_number, course_name, is_delete from course_info where course_number='$editCourseNumber'";
// 连接数据库，并查询
$result = mysqli_query($GLOBALS['conn'], $querySql);

//echo $result_config;
if (mysqli_num_rows($result) > 0) {
	echo "
<script>
    alert('该课程编号已存在，请重新输入！');
    history.go(-1);
</script>";
}else {
    $now = date('Y-m-d H:i:s', time());
    $editSql = "UPDATE course_info set update_time = '$now', course_number = '$editCourseNumber' ,course_name = '$editCourseName' where id = '$id'";
    if (mysqli_query($GLOBALS['conn'], $editSql)) {
        echo "
            <script>
                alert('修改成功！');
                window.location.href=document.referrer;
            </script>
        ";
    } else {
        echo "
            <script> 
                alert('修改失败！');
                history.back();
            </script>
        ";
    }

}

